package com.wngbms.redisson;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RDelayedQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@RestController
public class Producer {

    @Autowired
    RDelayedQueue<String> delayedQueue;

    AtomicInteger atomicInteger = new AtomicInteger();

    @GetMapping("/produce")
    public String produce(@RequestParam String msg) {

        log.info("offer:[{}]", msg);
        delayedQueue.offer(msg , 50, TimeUnit.SECONDS);

        return "success";
    }

    @GetMapping("/remove")
    public String remove(@RequestParam String msg) {
        log.info("remove:{}", msg);
        delayedQueue.remove(msg);
        return "success";
    }

}
